//
//  QuickLogin.m
//  ArtCircle
//
//  Created by sunbin on 2017/5/18.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "QuickLogin.h"


@interface QuickLogin ()
@property (nonatomic ,strong) TwoInputBox *two;

@end

@implementation QuickLogin
{}


- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    
    NSLog(@"%@" ,self.navigationController.viewControllers);
    
    
    
    
    self.two.account.text = [_params objectForKey:@"phone"];

    [self.navigationController.view showLoadFinish:_msg showLoc:bottom];
    [[NSNotificationCenter defaultCenter] postNotificationName:FIRSTTIMECOUBTDOWN object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"输入验证码";
    
     _two = self.contentView.inputBoxView.two;
    [_two.configBtn setTitle:@"进入艺圈人" forState:UIControlStateNormal];

    WEAKSELF;
    _two.nextStepHandler = ^(NSString *account, NSString *code, NSInteger make ,UIButton *sender) {
        [weakSelf.navigationController.view showLoading:@[@"正在发送",@"正在登录"][make]];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [weakSelf.navigationController.view hideHUD];
 // 发送验证码 登录 若登录成功就环信登录（获取id登录）
            [[AccountManage sharedAccountManage] request:make apiTy:API_CodeLogin params:@[weakSelf.params,@{@"phone":account,@"code":code}][make] success:^(NSDictionary *results, NSString *successMsg) {

                NSLog(@"%@" ,results);


                make==0?
                [weakSelf resentCountdown:sender msg:successMsg]:
                [[EaseMobManage sharedEaseMobManage]
                 loginWithUsername:IF_NULL_TO_STRING([results objectForKey:@"id"])
                 password         :IF_NULL_TO_STRING([results objectForKey:@"hxPsw"]) success:^(NSString *successMsg) {
                    
#pragma make 登录成功 跳转 保存数据 保存用户的账号密码 id 数据
                    
                    [weakSelf quickLoginCompleDataSaveAccount:account uid:IF_NULL_TO_STRING([results objectForKey:@"id"]) data:results];
                                        
                    ESTabBarController *main = [MainViewController bounceBarItems];
                    [weakSelf presentViewController:main animated:YES completion:^{
                        [main.navigationController.view showSuccess:@"登录成功"];
                    }];
                } failed:^(NSString *msg) {
                    NSLog(@"失败=%@" ,msg);
                }];
                
            } failed:^(WrapperEnumError errorty, NSString *msg) {
                [weakSelf.navigationController.view showError:msg];
            }];
        });
    };
    
}


- (void)resentCountdown:(UIButton *)sender msg:(NSString *)msg{

    [self.navigationController.view showSuccess:msg];
    [sender startTime:59 title:@"重新发送(60s)" waitTittle:@"s" respond:^(BOOL isPlayComple) {
        if (isPlayComple) {
            
        }
    }];
}



- (BOOL)isShowAuthorizedLoginView {
    return YES;
}

- (BOOL)isShowAccountHeaderView {
    return YES;
}

- (InputBoxType)getInputBoxType {
    return InputBoxTypeTwo;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end
